package cn.xscrum.demo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import cn.xscrum.common.annotation.Log;
import cn.xscrum.common.enums.BusinessType;
import cn.xscrum.demo.domain.Costmonth;
import cn.xscrum.demo.service.ICostmonthService;
import cn.xscrum.common.core.controller.BaseController;
import cn.xscrum.common.core.domain.AjaxResult;
import cn.xscrum.common.utils.poi.ExcelUtil;
import cn.xscrum.common.core.page.TableDataInfo;

/**
 * 换乘付款方式数据分析Controller
 * 
 * @author cyb
 * @date 2020-11-26
 */
@Controller
@RequestMapping("/demo/costmonth")
public class CostmonthController extends BaseController
{
    private String prefix = "demo/costmonth";

    @Autowired
    private ICostmonthService costmonthService;

    @RequiresPermissions("demo:costmonth:view")
    @GetMapping()
    public String costmonth()
    {
        return prefix + "/costmonth";
    }

    /**
	 * 查询换乘付款方式数据分析列表
     */
    @RequiresPermissions("demo:costmonth:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Costmonth costmonth)
    {
        startPage();
        List<Costmonth> list = costmonthService.selectCostmonthList(costmonth);
        return getDataTable(list);
    }

    /**
	 * 导出换乘付款方式数据分析列表
     */
    @RequiresPermissions("demo:costmonth:export")
    @Log(title = "换乘付款方式数据分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Costmonth costmonth)
    {
        List<Costmonth> list = costmonthService.selectCostmonthList(costmonth);
        ExcelUtil<Costmonth> util = new ExcelUtil<Costmonth>(Costmonth.class);
        return util.exportExcel(list, "costmonth");
    }

    /**
	 * 新增换乘付款方式数据分析
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
	 * 新增保存换乘付款方式数据分析
     */
    @RequiresPermissions("demo:costmonth:add")
    @Log(title = "换乘付款方式数据分析", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Costmonth costmonth)
    {
        return toAjax(costmonthService.insertCostmonth(costmonth));
    }

    /**
	 * 修改换乘付款方式数据分析
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Costmonth costmonth = costmonthService.selectCostmonthById(id);
        mmap.put("costmonth", costmonth);
        return prefix + "/edit";
    }

    /**
	 * 修改保存换乘付款方式数据分析
     */
    @RequiresPermissions("demo:costmonth:edit")
    @Log(title = "换乘付款方式数据分析", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Costmonth costmonth)
    {
        return toAjax(costmonthService.updateCostmonth(costmonth));
    }

    /**
	 * 删除换乘付款方式数据分析
     */
    @RequiresPermissions("demo:costmonth:remove")
    @Log(title = "换乘付款方式数据分析", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(costmonthService.deleteCostmonthByIds(ids));
    }
}
